package com.hu.thread;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;

import java.util.Random;
import java.util.concurrent.Future;

/**
 * @author 00355760
 * @功能：
 * @版本： V1
 * @版权： 信息技术有限公司（http://www.mychery.com/）
 * @作者： 磐石战队开发组  00355760
 * @日期： 2024/12/18 16:21
 */
public class Task2 {

    private static final Random random =new Random();

    public Future<String> doTaskFour() throws Exception {
        System.out.println("开始做任务四");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务四，耗时：" + (end - start) + "毫秒");
        return new AsyncResult<>("任务四完成");
    }

    public Future<String> doTaskFive() throws Exception {
        System.out.println("开始做任务五");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务五，耗时：" + (end - start) + "毫秒");
        return new AsyncResult<>("任务五完成");
    }

    public Future<String> doTaskSix() throws Exception {
        System.out.println("开始做任务六");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(10000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务六，耗时：" + (end - start) + "毫秒");
        return new AsyncResult<>("任务六完成");
    }
}
